#include "Frustum.h"

namespace DreamEngine
{

CFrustum::CFrustum(const CString& name, ProjectionType type/*=PT_PERSPECTIVE*/):
	m_type(type),
	m_width(1024),
	m_height(768),
	m_fovY(MATH_PI/4),
	m_near(1.0f),
	m_far(1000.0f)
{
	m_projectAspectRatio = m_height/m_width;

	UpdateProjection();

	m_isProjectChanged = true;
}


CFrustum::~CFrustum(void)
{

}

void CFrustum::SetProjectionType(ProjectionType type)
{
	m_type = type;
	UpdateProjection();
}

void CFrustum::SetFOVy(float fovy)
{
	m_fovY = fovy;
	UpdateProjection();
}

//void CFrustum::SetAspectRatio(float aspectRatio)
//{
//	m_projectAspectRatio = aspectRatio;
//	UpdateProjection();
//}

void CFrustum::SetNearClipDistance(float nearDist)
{
	m_near = nearDist;
	UpdateProjection();
}

void CFrustum::SetFarClipDistance(float farDist)
{
	m_far = farDist;
	UpdateProjection();
}

void CFrustum::SetWidth(float width)
{
	m_width = width;
	m_projectAspectRatio = m_height/m_width;
	UpdateProjection();
}

void CFrustum::SetHeight(float height)
{
	m_height = height;
	m_projectAspectRatio = m_height/m_width;
	UpdateProjection();
}

void CFrustum::SetProChange(bool isChanged/* =false */)
{
	m_isProjectChanged = isChanged;
}

void CFrustum::UpdateProjection()
{
	if (m_type==PT_PERSPECTIVE)
	{
		CMatrix16::MatrixPerspectiveFovLH(&m_projectMatrix, m_fovY,\
			m_projectAspectRatio, m_near, m_far);
	}
	else
	{
		//CMatrix16OrthoLH(&m_projectMatrix, m_width, m_height,\
			//m_near, m_far);
	}
	m_isProjectChanged = true;
}

}

